﻿using System;
using System.Collections.Generic;
using Model.Interfaces;
using Model.ModelEventArgs;

namespace Model.NotifyingCollections
{
    public class NotifyingModelHashMap : HashSet<IModel>
    {
        public event EventHandler<ModelItemEventArgs> AddedItemEvent;
        public event EventHandler<ModelItemEventArgs> RemovedItemEvent;

        public new bool Add(IModel item)
        {
            if (!base.Add(item))
                return false;
            if (AddedItemEvent != null)
                AddedItemEvent(this, new ModelItemEventArgs{ModelItem = item});
            return true;
        }

        public new bool Remove(IModel item)
        {
            if (!base.Remove(item))
                return false;
            if (RemovedItemEvent != null)
                RemovedItemEvent(this, new ModelItemEventArgs { ModelItem = item });
            return true;
        }

        public new void Clear()
        {
            throw new NotSupportedException();
        }

        public new int RemoveWhere(Predicate<IModel> predicate)
        {
            throw new NotSupportedException();
        } 
    }
}
